package com.aliang.shopping.service.impl;

import com.aliang.shopping.common.PageResult;
import com.aliang.shopping.common.ResultCodeEnum;
import com.aliang.shopping.exception.DataException;
import com.aliang.shopping.mapper.OperationLogMapper;
import com.aliang.shopping.model.converter.CommonConverter;
import com.aliang.shopping.model.converter.OperationLogConverter;
import com.aliang.shopping.model.dto.common.PageDTO;
import com.aliang.shopping.model.po.OperationLog;
import com.aliang.shopping.model.vo.operationLog.OperationLogExportVO;
import com.aliang.shopping.model.vo.operationLog.OperationLogVO;
import com.aliang.shopping.service.OperationLogService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author ShiBaLover
* @description 针对表【operation_log(操作日志表)】的数据库操作Service实现
* @createDate 2024-10-18 12:17:10
*/
@Service
@AllArgsConstructor
public class OperationLogServiceImpl extends ServiceImpl<OperationLogMapper, OperationLog>
    implements OperationLogService {
    private final CommonConverter<OperationLogVO> commonConverter = new CommonConverter<>();

    private final OperationLogConverter operationLogConverter;

    @Override
    public PageResult<OperationLogVO> selectPage(PageDTO pageDTO) {
        //查询数据
        IPage<OperationLogVO> page = new Page<>(pageDTO.getPageNum(), pageDTO.getPageSize());
        IPage<OperationLogVO> mapperPage = this.baseMapper.getPage(page, pageDTO);
        //转换数据

        return commonConverter.toPageResult(mapperPage);
    }

    @Override
    public List<OperationLogExportVO> getExportList(PageDTO pageDTO) {
        List<OperationLogVO> list = this.baseMapper.getVoList(pageDTO);
        if (list.isEmpty()) {
            throw new DataException(ResultCodeEnum.NOT_QUERY_RESULT);
        }
        //转换数据
        return operationLogConverter.toImportDTOList(list);
    }

}




